import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/SubCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import CartList from '@/views/CartList/index.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: import('../views/Layout/index.vue'),
      children: [
        {
          path: '',
          name: 'home',
          component: import('../views/Home/index.vue'),
        },
        {
          path: '/category/:id',
          name: 'category',
          component: Category,
        },
        {
          path: 'category/sub/:id',
          name: SubCategory,
          component: SubCategory
        },
        {
          path: '/detail/:id',
          name: Detail,
          component: Detail
        },
        {
          path:'/cartList',
          name:'cartList',
          component: CartList
        }
      ]
    },
    {
      path: '/login',
      component: Login,
    }
  ],
  //定制路由滚动行为，切换路由滚轮回到顶部
  scrollBehavior () {
    return {
      top: 0
    }
  }
})

export default router
